from flask import Flask
from flask import request,jsonify
import json
import image_service

app = Flask(__name__)

image_handle = image_service.createImageService()

@app.route("/")
def hello_redirect():
    return "<p>You can request /jkai !</p>"

@app.route("/jkai")
def hello_jkai():
    return "<p>Hello, Nothing here!</p>"

@app.route("/jkai/image_detect", methods=['GET', 'POST'])
def image_obj_detect():
    req = json.loads(request.data)
    image_url = req['image_url']
    image_data = req['image_data']
    print("image_url: ", image_url)
    res_dec = image_handle.detect_obj(image_data)
    res = {
        "result":res_dec
    }
    return jsonify(res)